package com.ruoyi.project.dict.cizunew.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.dict.cizunew.domain.Cizu;
import com.ruoyi.project.dict.cizunew.service.ICizuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * cizunewController
 *
 * @author shixiangwen
 * @date 2020-06-16
 */
@Controller
@RequestMapping("/dict/cizunew")
public class CizuController extends BaseController {
    private String prefix = "dict/cizunew";

    @Autowired
    private ICizuService cizuService;

    @RequiresPermissions("dict:cizunew:view")
    @GetMapping()
    public String cizunew() {
        return prefix + "/cizunew";
    }

    /**
     * 查询cizunew列表
     */
    @RequiresPermissions("dict:cizunew:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Cizu cizu) {
        startPage();
        List<Cizu> list = cizuService.selectCizuList(cizu);
        return getDataTable(list);
    }

    /**
     * 导出cizunew列表
     */
    @RequiresPermissions("dict:cizunew:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Cizu cizu) {
        List<Cizu> list = cizuService.selectCizuList(cizu);
        ExcelUtil<Cizu> util = new ExcelUtil<Cizu>(Cizu.class);
        return util.exportExcel(list, "cizunew");
    }

    /**
     * 新增cizunew
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存cizunew
     */
    @RequiresPermissions("dict:cizunew:add")
    @Log(title = "cizunew", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Cizu cizu) {
        return toAjax(cizuService.insertCizu(cizu));
    }

    /**
     * 修改cizunew
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        Cizu cizu = cizuService.selectCizuById(id);
        mmap.put("cizu", cizu);
        return prefix + "/edit";
    }

    @GetMapping("/view/{id}")
    public String view(@PathVariable("id") Long id, ModelMap mmap) {
        Cizu cizu = cizuService.selectCizuById(id);
        mmap.put("cizu", cizu);
        return prefix + "/view";
    }

    @GetMapping("/viewkkc/{id}")
    public String viewkkc(@PathVariable("id") Long id, ModelMap mmap) {
        Cizu cizu = cizuService.selectCizuById(id);
        mmap.put("cizu", cizu);
        return prefix + "/viewkkc";
    }

    /**
     * 修改保存cizunew
     */
    @RequiresPermissions("dict:cizunew:edit")
    @Log(title = "cizunew", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Cizu cizu) {
        return toAjax(cizuService.updateCizu(cizu));
    }

    /**
     * 删除cizunew
     */
    @RequiresPermissions("dict:cizunew:remove")
    @Log(title = "cizunew", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(cizuService.deleteCizuByIds(ids));
    }
}
